﻿<Window x:Class="WorkingTime.Classes.View.WorkingTimeWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WorkingTime"
        xmlns:converter="clr-namespace:WorkingTime.Classes.Converter"
        mc:Ignorable="d"
        Title="Working Time" MinWidth="400" Width="400"
        Icon="../../Images/AppIcon/Clock.ico">
    <Window.Resources>
        <converter:SelectedConverter x:Key="SelectedConverter"/>
        <converter:TimeSpanConverter x:Key="TimeSpanConverter"/>
    </Window.Resources>
    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <GroupBox Grid.Row="0" Header="New Project">
            <TextBox x:Name="TextBoxNewProjectName" Grid.Column="1" LostFocus="TextBoxLostFocus">
                <TextBox.InputBindings>
                    <KeyBinding Command="{Binding AddProjectCommand}" CommandParameter="{Binding ElementName=TextBoxNewProjectName, Path=Text}" Key="Enter" />
                </TextBox.InputBindings>
            </TextBox>
        </GroupBox>

        <GroupBox Grid.Row="1" Header="Select Project">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="5" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <ComboBox Grid.Column="0" x:Name="ComboBoxSelectedProject" ItemsSource="{Binding Projects}" SelectedItem="{Binding ActiveProject}" />
                <Button Grid.Column="2" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Command="{Binding DeleteProjectCommand}">
                    <Image  Source="../../Images/Icons/Close_24.png" Height="16" ToolTip="Delete this Project"/>
                </Button>
            </Grid>
        </GroupBox>

        <GroupBox Grid.Row="2" Header="{Binding ActiveProject}" HeaderStringFormat="Actual Project: {0}">
            <Grid >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid Grid.Row="0" Margin="0, 0, 0, 5" Visibility="{Binding ElementName=ComboBoxSelectedProject, Path=SelectedItem, Converter={StaticResource SelectedConverter}}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="5" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="5" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Label Grid.Column="0" Content="{Binding ActiveProject.TotalTime, Converter={StaticResource TimeSpanConverter}}" ContentStringFormat="Total Time: {0}" />
                    <Button Grid.Column="2" Content="Start" Command="{Binding SetStartCommand}" />
                    <Button Grid.Column="4" Content="Stop" Command="{Binding SetStopCommand}"/>
                </Grid>

            
                <DataGrid Grid.Row="1" ItemsSource="{Binding ActiveProject.WorkTimes}" IsReadOnly="True" AutoGenerateColumns="False">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Start" Binding="{Binding StartTime, StringFormat=HH\\:mm\\:ss}" />
                        <DataGridTextColumn Header="Stop" Binding="{Binding StopTime, StringFormat=HH\\:mm\\:ss}" />
                        <DataGridTextColumn Header="Duration" Binding="{Binding Duration, StringFormat=hh\\:mm\\:ss}" />
                    </DataGrid.Columns>
                </DataGrid>
            </Grid>
        </GroupBox>
    </Grid>
</Window>
